home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / Include / ds3100.md / netLEInt.h < prev    next >
C/C++ Source or Header  |  1989-07-08  |  10KB  |  326 lines

  1. /*
  2.  * netLEInt.h --
  3.  *
  4.  *    External definitions for the Am7990 (LANCE) ethernet controller.
  5.  * The description of the definitions here come from AMD Am7990 LANCE
  6.  * data sheet (Publication 05698 Rev B) and the Am7990 Techincal Manual.
  7.  *
  8.  * Copyright (C) 1989 by Digital Equipment Corporation, Maynard MA
  9.  *
  10.  *            All Rights Reserved
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its 
  13.  * documentation for any purpose and without fee is hereby granted, 
  14.  * provided that the above copyright notice appear in all copies and that
  15.  * both that copyright notice and this permission notice appear in 
  16.  * supporting documentation, and that the name of Digital not be
  17.  * used in advertising or publicity pertaining to distribution of the
  18.  * software without specific, written prior permission.  
  19.  *
  20.  * Digitial disclaims all warranties with regard to this software, including
  21.  * all implied warranties of merchantability and fitness.  In no event shall
  22.  * Digital be liable for any special, indirect or consequential damages or
  23.  * any damages whatsoever resulting from loss of use, data or profits,
  24.  * whether in an action of contract, negligence or other tortious action,
  25.  * arising out of or in connection with the use or performance of this
  26.  * software.
  27.  *
  28.  * $Header: netLEInt.h,v 1.2 89/04/03 15:16:12 mnelson Exp $ SPRITE (DECWRL)
  29.  */
  30.  
  31. #ifndef _NETLEINT
  32. #define _NETLEINT
  33.  
  34. #include "netEther.h"
  35. #include "net.h"
  36. #include "netInt.h"
  37.  
  38. /*
  39.  * Defined constants:
  40.  *
  41.  * NET_LE_CONTROL_REG_ADDR    The address of the control register for the 
  42.  *                ethernet chip.
  43.  * NET_LE_NUM_RECV_BUFFERS      The number of buffers that we have to receive
  44.  *                   packets in. Also, number of receive ring 
  45.  *                descriptors. It must be between 1 and 128 and
  46.  *                be a power of TWO.
  47.  * NET_LE_NUM_RECV_BUFFERS_LOG2    log base 2 of NET_LE_NUM_RECV_BUFFERS.
  48.  * NET_LE_NUM_XMIT_BUFFERS      The number of buffer descriptors that are used
  49.  *                   for a transmitted packet.  Also, number of xmit
  50.  *                ring descriptors. It must be between 1 and 
  51.  *                128 and    be a power of TWO.
  52.  * NET_LE_NUM_XMIT_BUFFERS_LOG2    log base 2 of NET_LE_NUM_XMIT_BUFFERS.
  53.  * NET_LE_RECV_BUFFER_SIZE      The size of each receive buffer. We make the
  54.  *                buffer big enough to hold the maximum size
  55.  *                ethernet packet + CRC check. This is 1514 +
  56.  *                4 = 1518 bytes. We round it to the nears 1/2 K
  57.  *                boundry to get 1536.
  58.  *            
  59.  * NET_LE_MIN_FIRST_BUFFER_SIZE    The smallest buffer that can be used for the
  60.  *                first element of a chain transmission.
  61.  *                If the first piece of a message is smaller than  *                this then it gets copied to other storage and
  62.  *                made the minimum size.
  63.  * NET_LE_NUM_XMIT_ELEMENTS     The number of elements to preallocate for the 
  64.  *                   retransmission queue.
  65.  */
  66.  
  67. #define NET_LE_CONTROL_REG_ADDR        0xB8000000
  68.  
  69. #define    NET_LE_NUM_RECV_BUFFERS_LOG2    4
  70. #define    NET_LE_NUM_RECV_BUFFERS        (1 << NET_LE_NUM_RECV_BUFFERS_LOG2)
  71.  
  72. #define    NET_LE_NUM_XMIT_BUFFERS_LOG2    0
  73. #define    NET_LE_NUM_XMIT_BUFFERS        (1 << NET_LE_NUM_XMIT_BUFFERS_LOG2)
  74.  
  75.  
  76. #define    NET_LE_RECV_BUFFER_SIZE        1536
  77. #define NET_LE_MIN_FIRST_BUFFER_SIZE    100
  78.  
  79. #define    NET_LE_NUM_XMIT_ELEMENTS    32
  80.  
  81. /*
  82.  * Buffer size from the chips point of view.
  83.  */
  84. #define NET_LE_DMA_BUF_SIZE        0x20000
  85. #define NET_LE_DMA_CHIP_ADDR_MASK    (NET_LE_DMA_BUF_SIZE - 1)
  86. #define NET_LE_DMA_BUFFER_ADDR        0xB9000000
  87.  
  88. /*
  89.  * Macros for converting chip to cpu and cpu to chip addresses.
  90.  */
  91. #ifdef notdef
  92. #define BUF_TO_ADDR(base, offset) ((unsigned short *) ((unsigned)base + offset * 2))
  93. #define    BUF_TO_CHIP_ADDR(addr) (0xB9000000 | (((unsigned)(addr) & NET_LE_DMA_CHIP_ADDR_MASK) >> 1))
  94. #endif
  95. char    *BUF_TO_ADDR();
  96. unsigned BUF_TO_CHIP_ADDR();
  97.  
  98. #define    CHIP_TO_BUF_ADDR(addr) ((unsigned short *) ((((unsigned)addr & NET_LE_DMA_CHIP_ADDR_MASK) << 1) | 0xB9000000))
  99.  
  100. /*
  101.  * The LANCE chip has four control and status registers that are selected by a
  102.  * register address port (RAP) register. The top 14 bits of RAP are reserved
  103.  * and read as zeros. The register accessable in the register data port (RDP)
  104.  * is selected by the value of the RAP. (page 15)
  105.  */
  106.  
  107. typedef struct NetLE_Reg {
  108.     unsigned short    dataPort;    /* RDP */
  109.     unsigned short        : 14;    /* Reserved - must be zero */
  110.     unsigned short    addrPort: 2;    /* RAP */
  111. } NetLE_Reg;
  112.  
  113. /*
  114.  * Possible RAP values. (page15)
  115.  */ 
  116.  
  117. #define    NET_LE_CSR0_ADDR    0x0
  118. #define    NET_LE_CSR1_ADDR    0x1
  119. #define    NET_LE_CSR2_ADDR    0x2
  120. #define    NET_LE_CSR3_ADDR    0x3
  121.  
  122. /*
  123.  * Control and status register defintions.
  124.  *
  125.  * CSR0 - Register 0.
  126.  * Note that CSR0 is updated by ORing the previous and present value.
  127.  * See (page 16-17) for description of these bits.
  128.  * Bits of CSR0 fall into the following groups:
  129.  * (R0) - Read only - writing does nothing.
  130.  * (RC)    - Read and clear by writing a one - Writing zero does nothing.
  131.  * (RW) - Read and Write.
  132.  * (RW1) - Read and write with one only. 
  133.  */
  134.  
  135. /*
  136.  * Error bits
  137.  * NET_LE_CSR0_ERROR = BABBLE|COLLISION_ERROR|MISSED_PACKET|MEMORY_ERROR
  138.  */
  139.  
  140. #define    NET_LE_CSR0_ERROR        0x8000    /* Error summary - R0 */
  141. #define    NET_LE_CSR0_BABBLE        0x4000    /* Transmitter babble - RC */
  142. #define    NET_LE_CSR0_COLLISION_ERROR    0x2000    /* Late collision - RC */
  143. #define    NET_LE_CSR0_MISSED_PACKET    0x1000    /* Miss a packet - RC */
  144. #define    NET_LE_CSR0_MEMORY_ERROR    0x0800    /* Memory error - RC */
  145. /*
  146.  * Interrupt bits.
  147.  * NET_LE_CSR_INTR = RECV_INTR|XMIT_INTR|INIT_DONE|ERROR
  148.  */
  149. #define    NET_LE_CSR0_RECV_INTR        0x0400     /* Receiver interrupt - RC */
  150. #define    NET_LE_CSR0_XMIT_INTR        0x0200    /* Trasmit interrupt - RC */
  151. #define    NET_LE_CSR0_INIT_DONE        0x0100    /* Initialization done - RC */
  152. #define    NET_LE_CSR0_INTR        0x0080    /* Interrupt Summary - R0 */
  153. /*
  154.  * Enable bits.
  155.  */
  156. #define    NET_LE_CSR0_INTR_ENABLE        0x0040    /* Interrupt enable - RW */
  157. #define    NET_LE_CSR0_RECV_ON        0x0020    /* Receiver on - R0 */
  158. #define    NET_LE_CSR0_XMIT_ON        0x0010    /* Transmitter on - R0 */
  159. #define    NET_LE_CSR0_XMIT_DEMAND        0x0008    /* Sent now flag. - RW1 */
  160. #define    NET_LE_CSR0_STOP        0x0004    /* Stop and reset - RW1 */
  161. #define    NET_LE_CSR0_START        0x0002    /* (Re)Start after stop - RW1*/
  162. #define    NET_LE_CSR0_INIT        0x0001    /* Initialize - RW1 */
  163.  
  164. /*
  165.  * Control and status register 1 (CSR1) (page 18)
  166.  * CSR1 is the low order 16 bits of the address of the Initialization block.
  167.  * Note that the LSB must be zero.
  168.  */
  169.  
  170. /*
  171.  * Control and status register (CSR2) (page 18)
  172.  * CSR2 is the high order 16 bits of address of the Initialization block.
  173.  * Note that the top 8 bits are reserved and must be zero.
  174.  */
  175.  
  176. /*
  177.  * Control and status register (CSR3) (page 18)
  178.  * CSR3 defines the Bus Master interface.
  179.  */
  180. #define    NET_LE_CSR3_BYTE_SWAP        0x0004    /* Byte swap for us. - RW */
  181. #define    NET_LE_CSR3_ALE_CONTROL        0x0002    /* Signals active low - RW */
  182. #define    NET_LE_CSR3_BYTE_CONTROL    0x0001    /* Byte control - RW */
  183.  
  184. /*
  185.  * LE Initialization block.
  186.  */
  187. #define    NET_LE_INIT_MODE    0x0
  188. #define NET_LE_INIT_ETHER_ADDR    0x2
  189. #define NET_LE_INIT_MULTI_MASK    0x8
  190. #define NET_LE_INIT_RECV_LOW    0x10
  191. #define NET_LE_INIT_RECV_HIGH    0x12
  192. #define NET_LE_INIT_RECV_LEN    0x13
  193. #define NET_LE_INIT_XMIT_LOW    0x14
  194. #define NET_LE_INIT_XMIT_HIGH    0x16
  195. #define NET_LE_INIT_XMIT_LEN    0x17
  196.  
  197. #define NET_LE_INIT_SIZE        0x18
  198.  
  199. /*
  200.  * LE Net Recv messages descriptors
  201.  */
  202. #define NET_LE_RECV_BUF_ADDR_LOW    0x0
  203. #define NET_LE_RECV_STATUS        0x2
  204. #define NET_LE_RECV_BUF_SIZE        0x4
  205. #define NET_LE_RECV_PACKET_SIZE        0x6
  206. #define NET_LE_RECV_DESC_SIZE        8
  207.  
  208. /*
  209.  * Bits in the status.
  210.  */
  211. #define NET_LE_RECV_CHIP_OWNED        0x80
  212. #define NET_LE_RECV_ERROR        0x40
  213. #define NET_LE_RECV_FRAMING_ERROR    0x20
  214. #define NET_LE_RECV_OVER_FLOW_ERROR    0x10
  215. #define NET_LE_RECV_CRC_ERROR        0x80
  216. #define NET_LE_RECV_BUFFER_ERROR    0x40
  217. #define NET_LE_RECV_START_OF_PACKET    0x20
  218. #define NET_LE_RECV_END_OF_PACKET    0x10
  219. #define NET_LE_RECV_BUF_ADDR_HIGH    0x0f
  220.  
  221. /*
  222.  * LE Net Xmit messages descriptors (page 23-23)
  223.  */
  224. #define NET_LE_XMIT_BUF_ADDR_LOW    0x0
  225. #define NET_LE_XMIT_STATUS1        0x2
  226. #define NET_LE_XMIT_BUF_SIZE        0x4
  227. #define NET_LE_XMIT_STATUS2        0x6
  228. #define NET_LE_XMIT_DESC_SIZE        8
  229.  
  230. /*
  231.  * The status bits in the first status short.
  232.  */
  233. #define    NET_LE_XMIT_CHIP_OWNED        0x80
  234. #define NET_LE_XMIT_ERROR        0x40
  235. #define NET_LE_XMIT_RETRIES        0x10
  236. #define NET_LE_XMIT_ONE_RETRY        0x80
  237. #define NET_LE_XMIT_DEFERRED        0x40
  238. #define NET_LE_XMIT_START_OF_PACKET    0x20
  239. #define NET_LE_XMIT_END_OF_PACKET    0x10
  240. #define NET_LE_XMIT_BUF_ADDR_HIGH    0x0f
  241.  
  242. /*
  243.  * Bits in the second status short.
  244.  */
  245. #define NET_LE_XMIT_BUFFER_ERROR    0x80
  246. #define NET_LE_XMIT_UNDER_FLOW_ERROR    0x40
  247. #define NET_LE_XMIT_LATE_COLLISION    0x10
  248. #define NET_LE_XMIT_LOST_CARRIER    0x80
  249. #define NET_LE_XMIT_RETRY_ERROR        0x40
  250. #define NET_LE_XMIT_TDR_COUNTER        0x3f
  251.  
  252. /*
  253.  * Structure to hold all state information associated with one of these
  254.  * chips.
  255.  */
  256. typedef struct {
  257.     unsigned short    *regAddrPortPtr;/* Which register to read or write. */
  258.     unsigned short    *regDataPortPtr;/* The value to write or read from. */
  259.     Address        initBlockPtr;    /* Chip initialization block. */
  260.     /*
  261.      * Pointers for ring of receive buffers. 
  262.      */
  263.     Address        recvDescFirstPtr;/* Ring of receive desc start.*/
  264.     Address        recvDescNextPtr; /* Next receive desc to be filled. */
  265.     Address        recvDescLastPtr; /* Ring of receive descriptors end. */
  266.     /*
  267.      * Pointers for ring of transmit buffers. 
  268.      */
  269.     Address        xmitDescFirstPtr;/* Ring of xmit descriptors start.*/
  270.     Address        xmitDescNextPtr; /* Next xmit desc to be filled. */
  271.     Address        xmitDescLastPtr; /* Ring of xmit descriptors end. */
  272.  
  273.     List_Links        *xmitList;    /* Pointer to the front of the list of
  274.                        packets to be transmited. */
  275.     List_Links          *xmitFreeList;    /* Pointer to a list of unused 
  276.                        transmission queue elements. */
  277.     Boolean        transmitting;    /* Set if are currently transmitting a
  278.                        packet. */
  279.     Boolean        running;    /* Is the chip currently active. */
  280.     Net_EtherAddress    etherAddressBackward;    /* The ethernet address in 
  281.                          * reverse byte order. */
  282.     Net_EtherAddress    etherAddress;    /* The ethernet address */
  283. } NetLEState;
  284.  
  285. /*
  286.  * The state of all of the interfaces. 
  287.  */
  288.   
  289. extern    NetLEState    netLEState;
  290.  
  291.  
  292. /*
  293.  * General routines.
  294.  */
  295.  
  296. extern    Boolean    NetLEInit();
  297. extern    void    NetLEOutput();
  298. extern    void    NetLEIntr();
  299. extern    void    NetLERestart();
  300. extern    Address    NetLEMemAlloc();
  301.  
  302. extern    void    NetLEReset();
  303.  
  304. /*
  305.  * Routines for transmitting.
  306.  */
  307.  
  308. extern    void    NetLEXmitInit();
  309. extern    ReturnStatus    NetLEXmitDone();
  310. extern    void    NetLEXmitRestart();
  311.  
  312. /*
  313.  * Routines for the receive unit.
  314.  */
  315.  
  316. extern    void    NetLERecvInit();
  317. extern    ReturnStatus    NetLERecvProcess();
  318.  
  319.  
  320.  
  321. #endif _NETLEINT
  322.  
  323.  
  324.  
  325.  
  326.